package com.zonhar.autofeed.controller;

import com.zonhar.autofeed.common.R;
import com.zonhar.autofeed.service.DistConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/dist")
public class DistConfigController {

    @Autowired
    private DistConfigService distConfigService;

    /**
     * 获取参数配置
     * @return
     */
    @GetMapping("/list")
    public R list(){
        Map<String,Object> dataMap = distConfigService.getDistConfigMap();
        return R.ok().put("data",dataMap);
    }

    /**
     * 根据传感器名称获取配置
     * @return
     */
    @GetMapping("/getSensorList")
    public R getSensorList(String distGroupName){
        Map<String,Object> dataMap = distConfigService.getSensorListByDistGroupName(distGroupName);
        return R.ok().put("data",dataMap);
    }

    /**
     * 更新参数
     * @param params
     * @return
     */
    @PostMapping("/update")
    public R update(@RequestBody Map<String,Object> params){
        distConfigService.updateByMap(params);
        return R.ok();
    }

}
